from rest_framework import serializers
from .models import (Material, User, Supplyer, ReceiveRecords, Processor, WorkShop, RepertoryRecords, PayRecords,
                     BuyRecords, ReturnGoodsRecords)


# 用户
class UserSerializers(serializers.ModelSerializer):
    username = serializers.CharField(help_text='用户名')

    class Meta:
        model = User

        fields = [
            'id',
            'username',
            'is_superuser',
            'material_suppplier_info',
            'processor_info',
            'material_info',
            'apartment_info',
            'query_info',
            'repertory_info',
            'process_material_remain',
            'history_workshop_info',
            'cost_info',
            'pay_info',
            'history_info',
            'statistic_info',
            'repertory_bill_info',
            'pay_bill_info',
            'receive_info',
            'buy_process_info',
            'return_info',
        ]


# 原料
class MaterialSerializers(serializers.ModelSerializer):
    company_name = serializers.CharField(source='supplyer.company_name', help_text='公司名称')
    company_short_name = serializers.CharField(source='supplyer.company_short_name', help_text='公司的简称')
    material_kind_size = serializers.CharField(help_text='原料品种及规格')
    line_kind_size = serializers.CharField(help_text='白胚线品种及规格')
    number = serializers.CharField(help_text='批号')
    material_level = serializers.CharField(help_text='原料等级')
    comment_one = serializers.CharField(help_text='备注一')
    comment_two = serializers.CharField(help_text='备注二')

    class Meta:
        model = Material
        fields = [
            'id',
            'material_kind_size',
            'company_name',
            'company_short_name',
            'line_kind_size',
            'number',
            'material_level',
            'comment_one',
            'comment_two',
        ]


# 供应商
class SupplyerSerializers(serializers.ModelSerializer):
    company_name = serializers.CharField(help_text='公司名称')
    company_short_name = serializers.CharField(help_text='公司简称')
    company_address = serializers.CharField(help_text='公司地址')
    company_phone_number = serializers.CharField(help_text='公司电话号码')
    fax = serializers.CharField(help_text='传真号码')
    taxpayer_code = serializers.CharField(help_text='纳税人识别码')
    num = serializers.CharField(help_text='账号')
    other_account = serializers.CharField(help_text='其他账户')
    account_name = serializers.CharField(help_text='户名')
    account_bank = serializers.CharField(help_text='开户行')
    linkman = serializers.CharField(help_text='联系人')
    linkman_phone_number = serializers.CharField(help_text='联系人电话号码')
    linkman_mobile_number = serializers.CharField(help_text='联系人手机号码')
    comment_one = serializers.CharField(help_text='备注一')
    comment_two = serializers.CharField(help_text='备注二')

    class Meta:
        model = Supplyer
        fields = [
            'id',
            'company_name',
            'company_short_name',
            'company_address',
            'company_phone_number',
            'fax',
            'taxpayer_code',
            'num',
            'other_account',
            'account_name',
            'account_bank',
            'linkman',
            'linkman_phone_number',
            'linkman_mobile_number',
            'comment_one',
            'comment_two',

        ]


# 加工商
class ProcessorSerializers(serializers.ModelSerializer):
    company_name = serializers.CharField(help_text='公司名称')
    company_short_name = serializers.CharField(help_text='公司简称')
    company_address = serializers.CharField(help_text='公司地址')
    company_phone_number = serializers.CharField(help_text='公司电话号码')
    fax = serializers.CharField(help_text='传真号码')
    taxpayer_code = serializers.CharField(help_text='纳税人识别码')
    num = serializers.CharField(help_text='账号')
    other_account = serializers.CharField(help_text='其他账户')
    account_name = serializers.CharField(help_text='户名')
    account_bank = serializers.CharField(help_text='开户行')
    linkman = serializers.CharField(help_text='联系人')
    linkman_phone_number = serializers.CharField(help_text='联系人电话号码')
    linkman_mobile_number = serializers.CharField(help_text='联系人手机号码')
    comment_one = serializers.CharField(help_text='备注一')
    comment_two = serializers.CharField(help_text='备注二')

    class Meta:
        model = Processor
        fields = [
            'id',
            'company_name',
            'company_short_name',
            'company_address',
            'company_phone_number',
            'fax',
            'taxpayer_code',
            'num',
            'other_account',
            'account_name',
            'account_bank',
            'linkman',
            'linkman_phone_number',
            'linkman_mobile_number',
            'comment_one',
            'comment_two',

        ]


# 车间（部门）
class WorkShopSerializers(serializers.ModelSerializer):
    name = serializers.CharField(help_text='车间名称')
    status = serializers.CharField(help_text='状态')

    class Meta:
        model = WorkShop
        fields = [
            'id',
            'name',
            'status',
        ]


# 领用记录
class ReceiveRecordsSerializers(serializers.ModelSerializer):
    workshop = serializers.CharField(source='workshop.name', help_text='车间')
    supplyer = serializers.CharField(source='supplyer.company_short_name', help_text='供应商')
    material = serializers.CharField(source='material.material_kind_size', help_text='原料')
    receive_date = serializers.DateTimeField(help_text='领用日期')
    class_one_weight = serializers.DateTimeField(help_text='一等品重量')
    class_two_weight = serializers.DateTimeField(help_text='二等品重量')
    oil_silk_weight = serializers.DateTimeField(help_text='油丝重量')
    other_weight = serializers.DateTimeField(help_text='其他重量')
    comment_one = serializers.DateTimeField(help_text='备注一')
    comment_two = serializers.DateTimeField(help_text='备注二')

    class Meta:
        model = ReceiveRecords
        fields = [
            'id',
            'workshop',
            'supplyer',
            'material',
            'receive_date',
            'class_one_weight',
            'class_two_weight',
            'oil_silk_weight',
            'other_weight',
            'comment_one',
            'comment_two'
        ]


# 入库记录
class RepertoryRecordsSerializers(serializers.ModelSerializer):
    # 原料相关的信息
    material_number = serializers.CharField(source='material.number', help_text='原料批号')
    material_line_kind_size = serializers.CharField(source='material.line_kind_size', help_text='白胚线品种及规格')
    material_supplyer = serializers.CharField(source='material.supplyer.company_short_name', help_text='供应商简称')
    department = serializers.CharField(source='department.name', help_text='收货部门')
    entry_type = serializers.CharField(help_text='入库类型')
    date = serializers.DateTimeField(help_text='收货日期')
    class_one_weight = serializers.CharField(help_text='一等品重量')
    class_two_weight = serializers.CharField(help_text='二等品重量')
    oil_silk_weight = serializers.CharField(help_text='油丝重量')
    other_weight = serializers.CharField(help_text='其他重量')
    price = serializers.FloatField(help_text='单价')
    sum_cost = serializers.FloatField(help_text='总金额')
    cur_cost = serializers.FloatField(help_text='本次付款金额')
    carriage = serializers.FloatField(help_text='实付运费')
    comment_one = serializers.CharField(help_text='备注一')
    comment_two = serializers.CharField(help_text='备注二')

    class Meta:
        model = RepertoryRecords
        fields = [
            'material_number',
            'material_line_kind_size',
            'material_supplyer',
            'entry_type',
            'department',
            'date',
            'class_one_weight',
            'class_two_weight',
            'oil_silk_weight',
            'other_weight',
            'price',
            'sum_cost',
            'cur_cost',
            'carriage',
            'comment_one',
            'comment_two',
        ]


# 付款记录
class PayRecordsSerializers(serializers.ModelSerializer):
    payee = serializers.CharField(help_text='收款单位')
    account = serializers.CharField(help_text='收款账户')
    cost = serializers.CharField(help_text='付款金额')
    date = serializers.CharField(help_text='付款日期')
    abstract = serializers.CharField(help_text='摘要')
    comment = serializers.CharField(help_text='备注')

    class Meta:
        model = PayRecords
        fields = [
            'id',
            'payee',
            'account',
            'cost',
            'date',
            'abstract',
            'comment',
        ]


# 采购记录
class BuyRecordsSerializers(serializers.ModelSerializer):
    material_supplyer = serializers.CharField(source='material.supplyer.company_short_name', help_text='原料供应商简称')
    material_kind_size = serializers.CharField(source='material.material_kind_size', help_text='原料品种规格')
    material_number = serializers.CharField(source='material.number', help_text='原料批号')
    material_level = serializers.CharField(source='material.material_level', help_text='原料等级')
    material_line_kind_size = serializers.CharField(source='material.line_kind_size', help_text='白坯线品种规格')
    date = serializers.DateTimeField(help_text='采购日期')
    processor = serializers.CharField(source='processor.company_name', help_text='加工商')
    num = serializers.CharField(help_text='采购数量')
    each_weight = serializers.CharField(help_text='单包重量')
    buy_weight = serializers.CharField(help_text='采购重量')
    price = serializers.FloatField(help_text='单价')
    carriage = serializers.FloatField(help_text='运费')
    sum_cost = serializers.FloatField(help_text='应付金额')
    real_cost = serializers.FloatField(help_text='实付金额')
    process_cost_rate = serializers.CharField(help_text='加工损耗率')
    tray_num = serializers.CharField(help_text='塑料托盘个数')
    comment_one = serializers.CharField(help_text='备注一')
    comment_two = serializers.CharField(help_text='备注二')

    class Meta:
        model = BuyRecords
        fields = [
            'id',
            'material_supplyer',
            'material_kind_size',
            'material_number',
            'material_level',
            'material_line_kind_size',
            'date',
            'processor',
            'num',
            'each_weight',
            'buy_weight',
            'price',
            'carriage',
            'sum_cost',
            'real_cost',
            'process_cost_rate',
            'tray_num',
            'comment_one',
            'comment_two',
        ]


# 退货记录
class ReturnGoodsRecordsSerializers(serializers.ModelSerializer):
    material_supplyer = serializers.CharField(source='material.supplyer.company_short_name', help_text='原料供应商简称')
    material_kind_size = serializers.CharField(source='material.material_kind_size', help_text='原料品种规格')
    material_line_kind_size = serializers.CharField(source='material.line_kind_size', help_text='白坯线品种规格')
    material_number = serializers.CharField(source='material.number', help_text='原料批号')
    material_level = serializers.CharField(source='material.material_level', help_text='原料等级')
    processor = serializers.CharField(source='processor.company_short_name', help_text='委外加工单位简称')
    date = serializers.CharField(help_text='退货日期')
    number = serializers.CharField(help_text='数量')
    reason = serializers.CharField(help_text='退货原因')
    comment_one = serializers.CharField(help_text='备注一')
    comment_two = serializers.CharField(help_text='备注二')

    class Meta:
        model = ReturnGoodsRecords
        fields = [
            'id',
            'material_supplyer',
            'material_kind_size',
            'material_line_kind_size',
            'material_number',
            'material_level',
            'processor',
            'number',
            'date',
            'reason',
            'comment_one',
            'comment_two',
        ]
